package com.xdu.spm.Librarian.Service;

import com.xdu.spm.Dao.Entity.Librarian;
import com.xdu.spm.Dao.Interface.LibrarianDao;

import java.util.HashMap;
import java.util.Map;


//实现图书馆管理员登陆、修改密码、退出功能
public class LoginService {
    LibrarianDao librarianDao = new LibrarianDao();

    public Map<String,Object> LoginDetermine(String userId,String password){
        Map<String,Object> map = new HashMap<>();
        //调用查询数据库方法，进行密码比对，在map中添加信息
        try {
            Librarian librarian = librarianDao.findLibByAccount(userId);
            if (librarian == null){
                map.put("success",false);
                map.put("message","001");
            }
            else if (librarian.getPassword().equals(password)){
                map.put("success",true);
                map.put("message","000");
                map.put("name",librarian.getName());
                map.put("logo",librarian.getAvatar());
            }
            else {
                map.put("success",false);
                map.put("message","002");
            }

        }catch (Exception e){
            map.put("success",false);
            map.put("message","003");
        }

        return map;
    }
}
